package com.ruoyi.proSystem.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.proSystem.domain.ProMarketing;
import com.ruoyi.proSystem.service.IProMarketingService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 营销设置Controller
 *
 * @author ruoyi
 * @date 2024-07-28
 */
@RestController
@RequestMapping("/marketing")
public class ProMarketingController extends BaseController
{
    @Autowired
    private IProMarketingService proMarketingService;

    /**
     * 查询营销设置列表
     */
    @RequiresPermissions("proSystem:marketing:list")
    @GetMapping("/list")
    public TableDataInfo list(ProMarketing proMarketing)
    {
        startPage();
        List<ProMarketing> list = proMarketingService.selectProMarketingList(proMarketing);
        return getDataTable(list);
    }

    /**
     * 导出营销设置列表
     */
    @RequiresPermissions("proSystem:marketing:export")
    @Log(title = "营销设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProMarketing proMarketing)
    {
        List<ProMarketing> list = proMarketingService.selectProMarketingList(proMarketing);
        ExcelUtil<ProMarketing> util = new ExcelUtil<ProMarketing>(ProMarketing.class);
        util.exportExcel(response, list, "营销设置数据");
    }

    /**
     * 获取营销设置详细信息
     */
    @RequiresPermissions("proSystem:marketing:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(proMarketingService.selectProMarketingById(id));
    }

    /**
     * 新增营销设置
     */
    @RequiresPermissions("proSystem:marketing:add")
    @Log(title = "营销设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProMarketing proMarketing)
    {
        return toAjax(proMarketingService.insertProMarketing(proMarketing));
    }

    /**
     * 修改营销设置
     */
    @RequiresPermissions("proSystem:marketing:edit")
    @Log(title = "营销设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProMarketing proMarketing)
    {
        return toAjax(proMarketingService.updateProMarketing(proMarketing));
    }

    /**
     * 删除营销设置
     */
    @RequiresPermissions("proSystem:marketing:remove")
    @Log(title = "营销设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(proMarketingService.deleteProMarketingByIds(ids));
    }
}
